Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

143
Visualizações
Function is no longer found if I add "require" source

I have a function "loadDays()" that should be executed when the body-section is loaded:

<body onload="loadDays()">

In <script> I have my function loadDays():

<script>
    function loadDays() {
        // code
    }

Now I added src="https://requirejs.org/docs/release/2.3.5/minified/require.js" to the <script>-tag, to make use of require inside my function.

While it does recognize require then, it throws a new error:

"Uncaught ReferenceError: loadDays is not defined

at onload

What am I missing?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If <script> tag has src attribute, then any content inside this tag is ignored.

You should add 2 separate tags:

<script src="https://requirejs.org/docs/release/2.3.5/minified/require.js"></script>
<script>
    function loadDays() {
        // code
    }
</script>

about 4 years ago · Juan Pablo Isaza Relatório

0

I've checked requireJS, so you should actually do it like this, as they said in the docs:

<!DOCTYPE html>
<html>
    <head>
        <title>My Sample Project</title>
        <!-- data-main attribute tells require.js to load
             scripts/main.js after require.js loads. -->
        <script data-main="scripts/main" src="https://requirejs.org/docs/release/2.3.5/minified/require.js"></script>
    </head>
    <body>
        <h1>My Sample Project</h1>
    </body>
</html>

Then add a main.js file in the scripts folder, and put your function inside of it.

    function loadDays() {
        // code
    }
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda